Algorithm to generate 1000 distinct integers in the range [0,8000]?

Posted by The Last Ninja on Stack Overflow See other posts from Stack Overflow or by The Last Ninja
Published on 2010-04-04T21:53:54Z Indexed on 2010/04/04 22:03 UTC
Read the original article Hit count: 119

What are some alternative methods to generate 1000 distinct random integers in the range [0,8000] as opposed to the following:

  1. naive method: generating a number and checking if it's already in the array. O(n^2)
  2. linear shuffle: generate sequence 0 to 8000, shuffle, take the first 1000. O(n)

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about permutation